﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Configuration;
using BusinessObject;
using BusinessLogic;
using Utility;
using System.IO;

/// <summary>
/// Summary description for CommonFunction
/// </summary>
namespace WebTeamplate
{
    public class CommonFunction
    {
        public CommonFunction()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #region CategoryCode
        public static string DEFAULT_WAREHOUSE_CODE = "01";
        public static string DEFAULT_CHUNGLOAIXE_CODE = "02";  
        
        public static string DEFAULT_UNIT_CODE = "03";
        public static string DEFAULT_LOAIHANGHOA_CODE = "04";
        public static string DEFAULT_GENDER_CODE = "05";
        public static string DEFAULT_COUNTRY_CODE = "06";
        public static string DEFAULT_CURENCY_CODE = "07";
        public static string DEFAULT_VND_CURENCY = "VND";
        public static string DEFAULT_NHOMHANGHOA_CODE = "08";
        #endregion

      

        public static string DEFAULT_CREATE_USER_TEMPLATE = "CreateUser.txt";
        public static string DEFAULT_ADMIN_LANGUAGE = "vi-VN";
        public static string DEFAULT_COMMENT_REQUIREINPUT = "(<span class='commentRequireInput'>*</span>)";
        public static string DEFAULT_COMBOBOX_EMPTY_TEXT = " - - - ";       
        public static string DEFAULT_COMMAND_ADD = "add";
        public static string DEFAULT_COMMAND_EDIT = "edit";
        public static string DEFAULT_ACTIVE_IMAGEURL = "~/App_Themes/Admin/images/tick.png";
        public static string DEFAULT_DEACTIVE_IMAGEURL = "~/App_Themes/Admin/images/publish_x.png";
        public static string DEFAULT_SORTUP_IMAGEURL = "~/App_Themes/Admin/images/icon_sort_a_new.gif";
        public static string DEFAULT_SORTDOWN_IMAGEURL = "~/App_Themes/Admin/images/icon_sort_d_new.gif";
        public static string DEFAULT_SORTDOWN_EXPRESSION = "ASC";
        public static string DEFAULT_SORTUP_EXPRESSION = "DESC";
        public static string DEFAULT_ORDERDOWN_IMAGEURL = "~/App_Themes/Admin/images/uparrow.png";
        public static string DEFAULT_ORDERUP_IMAGEURL = "~/App_Themes/Admin/images/downarrow.png";

        public static string DEFAULT_UPLOAD_PRODUCT = "~/Upload/Product/";
        public static string DEFAULT_UPLOAD_PRODUCT_SMALL = "~/Upload/Product/Small/";
        public static string DEFAULT_UPLOAD_PRODUCT_LARGE = "~/Upload/Product/Large/";
      //  public static int DEFAULT_ADMIN_PAGE_SIZE = 20;
        public static int DEFAULT_OUTSITE_PAGE_SIZE = 5;
        public static int DEFAULT_ORDER_UP = 1;
        public static int DEFAULT_ORDER_DOWN = 0;
        public static int DEFAULT_MAX_SIZE_IMAGE_UPLOAD
        {
            get
            {
                int result = 0;
               
                return result;
            }
        }
        public static int DEFAULT_ADMIN_PAGE_SIZE
        {
            get
            {
                int result = 10;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["AdminPageSize"].ToString());
                    
                }
                catch
                {
                }
                return result;
            }
        }
        public static int DEFAULT_MAX_SIZE_DOCUMENT_UPLOAD
        {
            get
            {
                int result = 0;
                try
                {

                    //result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["MaxSizeUploadDocument"].ToString());
                   // result = SystemConfigUtil.Get().MaxSizeUploadDocument;
                }
                catch
                {
                }
                return result;
            }
        }      
       
        public static string ImageProductExtend
        {
            get
            {
                string result = ".gif;.jpg;.jpeg;";
                try
                {

                    result = ConfigurationSettings.AppSettings["ImageProductExtend"].ToString();

                }
                catch
                {
                }
                return result;
            }
        }
        public static int ImageProductWidth
        {
            get
            {
                int result = 300;
                try
                {

                    result =int.Parse(ConfigurationSettings.AppSettings["ImageProductWidth"].ToString());

                }
                catch
                {
                }
                return result;
            }
        }
        public static DateTime Now
        {
            get
            {
                return DateTime.Now;
            }
        }
        public static bool DEFAULT_SENDMAIL_CREATE_USER
        {
            get
            {
                string result = "0";
                try
                {

                    result = ConfigurationSettings.AppSettings["SendMailCreateUser"].ToString();
                }
                catch
                {
                }
                if (result == "0")
                    return false;
                return true;
            }
        }
        public static string DEFAULT_MAIL_SERVER_NAME
        {
            get
            {
                string result = string.Empty;
                try
                {

                   // result = ConfigurationSettings.AppSettings["MailServer"].ToString();
                   // result = SystemConfigUtil.GetMailConfig().ServerName;
                }
                catch
                {
                }
                return result;
            }
        }
        public static string DEFAULT_MAILFROM
        {
            get
            {
                string result = string.Empty;
                try
                {

                    //result = ConfigurationSettings.AppSettings["MailFrom"].ToString();
                   // result = SystemConfigUtil.GetMailConfig().FromEmailAddress;
                }
                catch
                {
                }
                return result;
            }
        }
        public static int DEFAULT_MAIL_SERVER_PORT
        {
            get
            {
                int result = 0;
                try
                {

                   // result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["MailServerPort"].ToString());
                 //   result = SystemConfigUtil.GetMailConfig().ServerPort;
                }
                catch
                {
                }
                return result;
            }
        }
        public static string DEFAULT_COMPANYNAME(string language)
        {
           
            return "";
        
        }
        public static string DEFAULT_SHOWROOMADDRESS(string language)
        {
           
            return string.Empty;

        }
        public static string DEFAULT_HEADOFFICEADDRESS(string language)
        {
          
            return string.Empty;

        }
        public static string DEFAULT_COMPANY_DEVELOP
        {
            get
            {
                string result = string.Empty;
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyDevelopName"].ToString();
                }
                catch
                {
                }
                return result;
            }
        }
        public static string DEFAULT_COMPANY_DEVELOP_WEB
        {
            get
            {
                string result = string.Empty;
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyDevelopWeb"].ToString();
                }
                catch
                {
                }
                return result;
            }
        }
        public static string DEFAULT_COMPANYWEB
        {
            get
            {
                string result = string.Empty;
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyWeb"].ToString();
                }
                catch
                {
                }
                return result;
            }
        }
        public static string DEFAULT_COMPANYSOLOGAN
        {
            get
            {
                string result = string.Empty;
                try
                {

                    result = ConfigurationSettings.AppSettings["Sologan"].ToString();
                }
                catch
                {
                }
                return result;
            }
        }
        public static int BoxNewPageSize
        {
            get
            {
                int result = 5;
                try
                {

                   // result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["BoxNewPageSize"].ToString());
                    //result = SystemConfigUtil.Get().DefaultBoxNewPageSize;
                }
                catch
                {
                }
                return result;
            }
        }
        public static int PHIEUNHAP_MAXROW_GENNARATE
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUNHAP_MAXROW_GENNARATE"].ToString());
                    
                }
                catch
                {
                    
                }
                if (result < 1)
                    result = 10;
                return result;
            }
        }
        public static int PHIEUNHAP_MAXROW_SHOW
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUNHAP_MAXROW_SHOW"].ToString());

                }
                catch
                {
                   
                }
                if (result > PHIEUNHAP_MAXROW_GENNARATE || result<1)
                    result = PHIEUNHAP_MAXROW_GENNARATE;
                return result;
            }
        }

        public static int PHIEUXUAT_MAXROW_GENNARATE
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUXUAT_MAXROW_GENNARATE"].ToString());

                }
                catch
                {

                }
                if (result < 1)
                    result = 10;
                return result;
            }
        }
        public static int PHIEUXUAT_MAXROW_SHOW
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUXUAT_MAXROW_SHOW"].ToString());

                }
                catch
                {

                }
                if (result > PHIEUXUAT_MAXROW_GENNARATE || result < 1)
                    result = PHIEUXUAT_MAXROW_GENNARATE;
                return result;
            }
        }

        public static int PHIEUCHUYENKHO_MAXROW_GENNARATE
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUCHUYENKHO_MAXROW_GENNARATE"].ToString());

                }
                catch
                {

                }
                if (result < 1)
                    result = 10;
                return result;
            }
        }
        public static int PHIEUCHUYENKHO_MAXROW_SHOW
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["PHIEUCHUYENKHO_MAXROW_SHOW"].ToString());

                }
                catch
                {

                }
                if (result > PHIEUCHUYENKHO_MAXROW_GENNARATE || result < 1)
                    result = PHIEUCHUYENKHO_MAXROW_GENNARATE;
                return result;
            }
        }

        public static int MAHH_LENGTH
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["MAHH_LENGTH"].ToString());
                    return result;

                }
                catch
                {

                }
                return 6;

            }
        }
        public static int WARNINGLEVEL2
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["WARNINGLEVEL2"].ToString());

                }
                catch
                {

                }
                if (result < 1)
                    result = 10;
                return result;
            }
        }
        public static int WARNINGLEVEL1
        {
            get
            {
                int result = 0;
                try
                {

                    result = ConvertValueObject.ParseInt(ConfigurationSettings.AppSettings["WARNINGLEVEL1"].ToString());

                }
                catch
                {

                }
                if (result < 1)
                    result = 3;
                return result;
            }
        }

        public static void InitStatusPublishForRadioButtonList(RadioButtonList rbl)
        {
            rbl.Items.Clear();
            rbl.Items.Add(new ListItem("Tất cả", string.Empty));
            rbl.Items.Add(new ListItem("Hiển thị","1"));
            rbl.Items.Add(new ListItem("Không hiển thị","0"));
            rbl.SelectedValue = string.Empty;
            // Base
        }
        public static void InitStatusStatusContactUSForRadioButtonList(RadioButtonList rbl)
        {
            rbl.Items.Clear();
            rbl.Items.Add(new ListItem("Tất cả", string.Empty));
            rbl.Items.Add(new ListItem("Đã xử lý", CommonFunction.DEFAULT_CONTACT_US_STATUS_FINISH));
            rbl.Items.Add(new ListItem("Chưa xử lý", CommonFunction.DEFAULT_CONTACT_US_STATUS_PENDING));
            rbl.SelectedValue = string.Empty;
            // Base
        }
        public static void InitStatusPublishForComboboxDetail(DropDownList drl)
        {
            drl.Items.Clear();
            //drl.Items.Add(new ListItem(DEFAULT_COMBOBOX_EMPTY_TEXT, string.Empty));
            drl.Items.Add(new ListItem("Hiển thị", "1"));
            drl.Items.Add(new ListItem("Không hiển thị", "0"));
            drl.SelectedValue ="1";
            // Base
        }
        public static void InitStatusPublishForComboboxDetail(DropDownList drl,string defaultSelect)
        {
            drl.Items.Clear();
            drl.Items.Add(new ListItem(DEFAULT_COMBOBOX_EMPTY_TEXT, string.Empty));
            drl.Items.Add(new ListItem("Hiển thị", "1"));
            drl.Items.Add(new ListItem("Không hiển thị", "0"));
            drl.SelectedValue = defaultSelect;
            // Base
        }
        public static void InitLanguageToDropList(DropDownList drlLanguage, bool addNullItem)
        {

          
        }

       
        public static void SetDisableAdminTextBox(TextBox txt, bool disable)
        {
            if (disable)
                txt.CssClass = "detailedViewTextBox_Disable";
            else txt.CssClass = "detailedViewTextBox";
            txt.Enabled = !disable;
        }
        public static string CompanyName
        {
            get
            {
                string result = "NAM THÁI";
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyName"].ToString();

                }
                catch
                {
                }
                return result;
            }
        }
        public static string CompanyAddress
        {
            get
            {
                string result = "230 Nguyễn Công Trứ, Quận 1";
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyAddress"].ToString();

                }
                catch
                {
                }
                return result;
            }
        }
        public static string CompanyTel
        {
            get
            {
                string result = "0937225625";
                try
                {

                    result = ConfigurationSettings.AppSettings["CompanyTel"].ToString();

                }
                catch
                {
                }
                return result;
            }
        }
        public static string GetTextLabel(Label _lbl)
        {
            if (_lbl.Text.Trim().Length <= 0)
                return string.Empty;
            string result;
            string title = _lbl.Text.Trim();
            title = title.Replace(CommonFunction.DEFAULT_COMMENT_REQUIREINPUT, "");
            //string strTmp = "(<span class='requireFields'>*</span>)
            if (title.EndsWith("(*):"))
            {
                //(<span class='requireFields'>*</span>)
                result = title.Substring(0, title.Length - 4);
            }

            if (title.EndsWith("(*):"))
            {
                //(<span class='requireFields'>*</span>)
                result = title.Substring(0, title.Length - 4);
            }
            else if (title.EndsWith(":"))
            {
                result = title.Substring(0, title.Length - 1);
            }

            else
            {
                result = title;
            }
            return result;
        }

        public static string GetValueFromQueryString(System.Web.UI.Page page, string key)
        {
            try
            {
                return page.Request.QueryString[key].ToString();
            }
            catch
            {
            }
            return string.Empty;
        }


        public static bool CheckRequireData(string languageID)
        {
            string requireLanguage = "en-US";
            if (requireLanguage.ToLower().Contains(languageID.ToLower()))
                return true;
            return false;
        }


        #region Validate Data
        public static bool CheckSGiaIsValid(string value)
        {
            double doublevalue = ConvertValueObject.ParseDouble(value);
            if (doublevalue < 0 || doublevalue > 99999999999.99)
                return false;
            return true;
        }
        public static bool CheckSImageValid(FileUpload ful)
        {
            if (ful.HasFile)
            {
                string exstendfile = System.IO.Path.GetExtension(ful.FileName).ToLower();
                if (IsApprovedImageFile(ful))
                    return true;
                return false;
            }
            return true;
        }
        /// <summary>
        /// Check size and file extention for image
        /// </summary>
        /// <param name="fileUpload"></param>
        /// <returns></returns>
        public static bool IsApprovedImageFile(FileUpload fileUpload)
        {
            bool result = true;
            string filePath = fileUpload.FileName;
            if (filePath.Length > 0)
            {
                int maxsizeupload = CommonFunction.DEFAULT_MAX_SIZE_IMAGE_UPLOAD * 1024;
                int filelength = fileUpload.PostedFile.ContentLength;
                if (filelength > 0 && filelength < maxsizeupload)
                {
                    string fileExtention = "." +  filePath.Substring(filePath.LastIndexOf(".") + 1) + ";";
                    result = CommonFunction.ImageProductExtend.ToLower().IndexOf(fileExtention.ToLower()) >= 0;
                }
                else
                {
                    result = false;
                }
            }
            return result;
        }
        public static bool IsApprovedDocumentFile(FileUpload fileUpload)
        {
            bool result = true;
           
            return result;
        }
        #endregion

        #region Define FolderURL
        public static int DEFAULT_SMALL_PRODUCT_IMAGE_WIDTH = 100;
        public static int DEFAULT_LARGE__PRODUCT_IMAGE_WIDTH = 190;
        public static int DEFAULT_LOGO_WIDTH = 200;
        public static int DEFAULT_CUSTOMER_WIDTH = 100;
        public static string DEFAULT_NOIMAGE_FOLDER = "noimages";//ten thu muc chua hinh noimager
        public static string DEFAULT_UPLOAD_FOLDER = "upload";//ten thu muc up load hinh
        public static string DEFAULT_LOGO_NOIMAGE_FOLDER = "logo";//thu muc chua hinh noimage cua logo
        public static string DEFAULT_CUSTOMER_NOIMAGE_FOLDER = "customer";//thu muc chua hinh noimage cua customer
        public static string DEFAULT_LOGO_NOIMAGE = "logonoimage.jpg";//noimage logo
        public static string DEFAULT_CUSTOMER_NOIMAGE = "logonoimage.jpg";//noimage customer
        public static string DEFAULT_UPLOAD_LOGO_FOLDER = "logo";//thu muc chua logo
        public static string DEFAULT_UPLOAD_CUSTOMER_FOLDER = "customer";//thu muc chua hinh customer
        public static string DEFAULT_UPLOAD_LOGO_ORIGINAL_FOLDER = "Original";//hinh goc
        public static string DEFAULT_UPLOAD_LOGO_VIEW_FOLDER = "View";//hinh show ngoai trang web
        public static string DEFAULT_UPLOAD_CUSTOMER_ORIGINAL_FOLDER = "Original";//hinh goc
        public static string DEFAULT_UPLOAD_CUSTOMER_VIEW_FOLDER = "View";//hinh show ngoai trang web

        public static string DEFAULT_UPLOAD_DOCUMENT_FOLDER = "Document";//thu muc chua Document

     
        public static string DEFAULT_SMALLPRODUCT_NOIMAGE
        {
            get
            {
                return string.Empty;
             //   return "upload/noimages/product/smallproduct_" + SystemConfigUtil.Get().DefaultProductNoImage;
                //= "upload/noimages/product/smallproduct.jpg";
            }
        }

        public static string DEFAULT_LARGEPRODUCT_NOIMAGE
        {
            get
            {
                return string.Empty;
              //  return "upload/noimages/product/largeproduct_" + SystemConfigUtil.Get().DefaultProductNoImage;
                //= "upload/noimages/product/smallproduct.jpg";
            }
            // = "upload/noimages/product/largeproduct.jpg";
        }

        public static string DEFAULT_TEMPLATE_MAIL_RECOVERYPASS = "Templatemail/RecoveryPass.txt";

        public static void CreateFolder(string path)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            catch
            { }
        }
        public static void DeleteFile(string _fullPath)
        {
            try
            {
                if (File.Exists(_fullPath))
                {
                    File.Delete(_fullPath);

                }
            }
            catch
            {
            }
        }
        #endregion

        #region Role


        #endregion

        #region Method For CheckBox List
        public static void CheckValuesCheckBox(string[] arr, CheckBoxList cbl)
        {
            foreach (ListItem item in cbl.Items)
            {
                if (IsExists(arr, item.Value))
                    item.Selected = true;
            }
        }
        public static bool IsExists(string[] arr, string value)
        {
            foreach (string v_Value in arr)
            {
                if (v_Value == value)
                    return true;
            }
            return false;
        }
        #endregion

        #region SubCategory
        public static string DEFAULT_CONTACT_US_STATUS_FINISH = "01";
        public static string DEFAULT_CONTACT_US_STATUS_PENDING = "00";
       
        public static void LoadSubCate(DropDownList drl, string categoryId, bool addNullItem)
        {
            List<SubCategoryResult> lstCate = SubCategoryUtil.GetAllByCategory(categoryId);
            drl.Items.Clear();
            if (addNullItem)
            {
                ListItem nullItem = new ListItem(BaseFunctions.COMBOBOX_NULL_VALUE, string.Empty);
                drl.Items.Add(nullItem);
            }
            if (lstCate == null)
                return;
            foreach (SubCategoryResult objCate in lstCate)
            {
                drl.Items.Add(new ListItem(objCate.SubCategoryName, objCate.SubCategoryId.ToString()));
            }

        }

        #endregion

        #region Read number
        public static string numberGroupSeparator = ".";
        public static string numberDecimalSeparator = ",";
        public static string ReadNumber(string value)
        {
            if (value.Contains(numberDecimalSeparator))
                return ReadOodNumber(value);
            return ReadIntNumber(value);           
        }
        private static string ReadOodNumber(string value)
        {
            string[] val=value.Split(char.Parse(numberDecimalSeparator));
            string nguyen = val[0].ToString();
            string le = val[1].ToString();
            string  docNguyen=ReadNumber(val[0].ToString());
            string docLe = ReadNumber(val[1].ToString());
            int l2 = val[1].ToString().Length;
            int intOld = int.Parse(val[1].ToString());
            int l1 = intOld.ToString().Length;
            if (l1 != l2)
            {
                int i = 0;
                while (i < l2 - l1)
                {
                    docLe = "không " + docLe;
                    i++;
                }
            }
            return docNguyen + " phẩy " + docLe;

        }
        private static string ReadIntNumber(string value)
        {
            value = value.Replace(numberGroupSeparator, "");
            long Num = 0;
            try
            {
                Num = long.Parse(value);
            }
            catch
            {
                return string.Empty;
            }
            return ReadNumber(Num);
        }
        public static string ReadNumber(long Num)
        {
           
            string result = string.Empty;
            if (Num == 0)
                return "không";
            string[] DL = new string[10];
            DL[1] = " một";
            DL[2] = " hai";
            DL[3] = " ba";
            DL[4] = " bốn";
            DL[5] = " năm";
            DL[6] = " sáu";
            DL[7] = " bảy";
            DL[8] = " tám";
            DL[9] = " chín";
            string[] TP = new string[4];
            int i = 0;
            int DuoiNgan = 0;
            byte HangDV = 0;
            byte HangChuc = 0;
            byte HangTram = 0;
            TP[1] = " ngàn";
            TP[2] = " triệu";
            TP[3] = " tỷ";

            i = 0;
            while ((i < TP.Length && Num > 0))
            {
                //vòng lap, có 4 vòng: < ngàn, , triêu, < ty và ty

                DuoiNgan = (int)(Num % 1000);
                //Lây 3 sô sau
                Num = Num / 1000;
                //Num Ða loai 3 sô sau

                HangDV = (byte)(DuoiNgan % 10);
                HangChuc = (byte)(DuoiNgan / 10 % 10);
                HangTram = (byte)(DuoiNgan / 100);
                // result " ba tram ngan" = 13 ký tu' = result nho nhât

                if (result.Length > 12 & DuoiNgan != 0)
                {
                    //Thêm dâu "," cho Ðep
                    result = TP[i] + "," + result;
                }
                // 2 câu lênh riêng, nêu dùng else, se tao ra "ty, triêu..
                // vì dùng Else se lây thêm các tri DuoiNgan = 0
                if (result.Length <= 12 & DuoiNgan != 0)
                {
                    //if(i==3 && Num>0)
                    //    result = "" + result;
                    //else
                    result = TP[i] + result;
                }
                i = i + 1;
                //sau khi xác Ðinh TP(i), i mo'i thêm 1

                switch (HangDV)
                {
                    case (1):
                        if (HangChuc > 1)
                            result = " mốt" + result;
                        else
                            result = " một" + result;
                        break;
                    case (5):
                        if (HangChuc == 0)
                            result = " năm" + result;
                        else
                            result = " lăm" + result;
                        break;
                    default:
                        result = DL[HangDV] + result;
                        break;
                }

                switch (HangChuc)
                {
                    case (1):
                        result = " mười" + result;
                        break;
                    case (0):
                        if ((Num != 0 | HangTram != 0) & HangDV != 0) result = " lẻ" + result;
                        break;
                    default:
                        result = DL[HangChuc] + " mươi" + result;
                        break;
                }

                switch (HangTram)
                {
                    case (0):
                        if (Num != 0 & (HangDV != 0 | HangChuc != 0)) result = " không trăm" + result;
                        if (Num != 0 & i > 2 & DuoiNgan == 0 & HangDV == 0 & HangChuc == 0 & HangTram == 0 & result.Length <= 12) result = "";
                        break;
                    default:
                        result = DL[HangTram] + " trăm" + result;
                        break;
                }
            }            
            // viêt Hoa
            result = Left(result, 1) + Right(result, result.Length - 1);
            return result;
        }
        public static string Left(string value, int len)
        {
            return value.Substring(0, len);
        }
        public static string Right(string value, int len)
        {
            return value.Substring(value.Length - len, len);
        }
        public static DateTime SetTime(DateTime data, int h, int m, int s)
        {
            DateTime result = new DateTime(data.Year, data.Month, data.Day, h, m, s);
            return result;

        }
        #endregion

    }
}
